package Java测试.编码4;

import java.lang.reflect.Array;

//4.数组[8,5,6,1,2,3,4,7],使用冒泡循环和选择排序完成从小到大进行排序
public class 冒泡排序 {
    public static void main(String[] args) {
        int [] arr={8,5,6,1,2,3,4,7};
        for (int i = 0; i <arr.length-1; i++) {
            for (int j = 0; j <arr.length-i-1; j++) {
                if (arr[j]>arr[j+1]){
                    int x=arr[j+1];
                    arr[j+1]=arr[j];
                    arr[j]=x;
                }
            }
        }
        for (int i = 0; i <arr.length; i++) {
            System.out.print(arr[i]);
        }
    }
}
